<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>tk首页</title>
		<link rel="stylesheet" href="static/css/reset.css">
		<link rel="stylesheet" href="static/css/common.css">
		<link rel="stylesheet" href="static/css/index.css">
		<script src="static/js/jquery-1.11.1.min.js"></script>
		<script src="static/js/index.js"></script>
	</head>
	<body ng-app="myApp" ng-controller="main">
		<header>
			<div class="top">
				<div class="w1070 padlr">
					<div class="fl left">
						全国服务热线：400-000-0000
					</div>
					<div class="fr right">
						<a href="" class="shou">设为首页</a>
						<a href="" >加入收藏</a>
					</div>
				</div>
			</div>
			<div class="bottom">
				<div class="w1070">
					<img src="static/images/logo.png" alt="" class="logo">
					<nav class="fr">
						<ul>
							<li  ng-repeat="v in nav_data" ng-class="{'active':$index==active}" ng-click="cla($index)">
								<a href="javascript:;" ui-sref="{{v.sref}}" ng-bind-html="nav_name(v.n_name);nav_dat"></a>
							</li>
						</ul>
					</nav>
				</div>
			</div>
		</header>
		<div class="min-h" ui-view>
			
		</div>
		
		<footer>
			<div class="footer_top">
				<p>	
					<span>关注我们：</span>
					<a href=""><img src="static/images/weibo.png" alt=""></a>
					<a href=""><img src="static/images/qq.png" alt=""></a>
					<a href=""><img src="static/images/wechat.png" alt=""></a>
				</p>
				<div class="clear"></div>
				<p class="q">
					<a href="">网站首页</a> •
					<a href="">新闻动态</a> •
					<a href="">关于我们</a> •
					<a href="">团队风采</a> •
					<a href="">联系我们</a> •
					<a href="">在线留言</a>        
				</p>
			</div>
			<div class="footer_bottom">
				©2015 TK科技有限公司&nbsp;&nbsp;版权所有沪ICP证13022560号-7 All Rights Reserved
			</div>
		</footer>
		<script src="static/js/angular.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="static/js/angular-ui-router.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			//默认最小高度
			$('.min-h').css('min-height',document.body.clientHeight/20-13.55+'rem');
			var app=angular.module('myApp',['ui.router']);
			app.config(function($stateProvider,$urlRouterProvider){
				$urlRouterProvider.when('',"index");
				$stateProvider
				.state('index',{
					url:"/index",
					templateUrl:"view/index.html",
					controller:"index",
				})
				.state('cp',{
					url:"/cp",
					templateUrl:"view/cp.html",
					controller:"cp",
				})
				.state('about',{
					url:"/about",
					templateUrl:"view/about.html",
					controller:"about",
				})
				.state('contact',{
					url:"/contact",
					templateUrl:"view/contact.html",
					controller:"contact",
				})
				.state('news',{
					url:"/news",
					templateUrl:"view/news.html",
					controller:"news",
				})
				.state('service',{
					url:"/service",
					templateUrl:"view/service.html",
					controller:"service",
				})
				.state('shop',{
					url:"/shop",
					templateUrl:"view/shop.html",
					controller:"shop",
				})
				.state('cp_detail',{
					url:"/cp_detail",
					templateUrl:"view/cp_detail.html",
					controller:"cp_detail",
					params:{'did':{}}
				})
			})
			app.controller('main',function($scope,$http,$sce){
				$http.post('api/data.php')
				.success(function(z){
					console.log(z);
					$scope.nav_data=z['nav'];
					$scope.nav_name=function(v){
						$scope.nav_dat=$sce.trustAsHtml(v);
					};
					//产品
					$scope.cp=z['cp'];
					//系列
					$scope.sort=z['sort'];
					$scope.p=z.p;
					$scope.next=z.next;
					$scope.prev=z.prev;
					//关于我们
					$scope.about_cnt=$sce.trustAsHtml(z.about.a_cnt);
					$scope.news=z.news;
				})
				//刷新默认选中ui-sref
				var arrq=["#/index","#/about","#/cp","#/service","#/news","#/shop","#/contact","#/cp_detail"];
				var qq=location.href;
				var suoyin=qq.indexOf('#/');
				var zhen=qq.substr(suoyin);
				$scope.active=0;
				if(zhen==arrq[0]){
					$scope.active=0;
				}else if(zhen==arrq[1]){
					$scope.active=1;
				}else if(zhen==arrq[2]){
					$scope.active=2;
				}else if(zhen==arrq[3]){
					$scope.active=3;
				}else if(zhen==arrq[4]){
					$scope.active=4;
				}else if(zhen==arrq[5]){
					$scope.active=5;
				}else if(zhen==arrq[6]){
					$scope.active=6;
				}else if(zhen==arrq[7]){
					$scope.active=5;
				}

				$scope.cla=function(i){
					$scope.active=i;
				}
			})
			app.controller('index',function($scope){
				
			})
			//产品中心
			app.controller('shop',function($scope,$state,$http){
				$scope.detail=function(did){
					$state.go('cp_detail',{'did':did});
				};
				$scope.active=0;
				$scope.sortid=function(sid){
					$http.post('api/data.php',{ssid:sid})
					.success(function(z){
						//console.log(z);
						$scope.cp=z['cp'];
						$scope.sid=sid;
						$scope.p=z.p;
						$scope.next=z.next;
						$scope.prev=z.prev;
					})
				}
				
				$scope.page=function(p,sid,like){
					//console.log(p);
					$http.post('api/data.php',{ssid:sid,p:p,like:like})
					.success(function(z){
						//console.log(z);
						$scope.cp=z['cp'];
						$scope.next=z.next;
						$scope.prev=z.prev;
					})
					$scope.active=p-1;
				}
				$scope.search=function(like){
					$http.post('api/data.php',{like:like})
					.success(function(z){
						$scope.cp=z['cp'];
						//console.log(z);
						$scope.p=z.p;
						$scope.next=z.next;
						$scope.prev=z.prev;
					})
					
				}
				$scope.change=function(like){
					$http.post('api/data.php',{like:like})
					.success(function(z){
						//console.log(z)
						$scope.lei=z.like_name_data;
						$scope.show=true;//显示数据库里面的产品名称
						if(like==''){//清空搜索框后
							$scope.lei='';
							$scope.show=false;
							$scope.sortid($scope.sid);//调用系列方法。还原产品列表
						}
					})
					$scope.xuan=function(v){
						//console.log(v);
						this.search(v);
						$scope.show=false;
					}
				}
				
			})
			app.controller('cp_detail',function($scope,$stateParams,$http,$sce){
				//console.log(did);
				if($stateParams.did.length==undefined){
					var did=1;
				}else{
					var did=$stateParams.did;
				}
				$http.post('api/data.php',{did:did})
				.success(function(response){
					//console.log(response);
					$scope.cp_detail=response['cp_detail'];
					$scope.detail=$sce.trustAsHtml(response['cp_detail'].p_detail);
					$scope.bimg=response['cp_detail'].p_bimg;
					if(response['cp_detail'].p_tejia!=''){
						$scope.price=response['cp_detail'].p_tejia;
					}else{
						$scope.price=response['cp_detail'].p_price;
					}
					$scope.totalprice=$scope.price;
				})
				$scope.huantu=function(i){
					$scope.bimg=i;
				}
				$scope.num=1;
				$scope.jian=function(){
					$scope.num=$scope.num>1?$scope.num-1:$scope.num;
					$scope.totalprice=$scope.num*$scope.price;
				}
				$scope.jia=function(){
					$scope.num=$scope.num<100?$scope.num+1:$scope.num;
					$scope.totalprice=$scope.num*$scope.price;
				}
				//返回两位小数
				function returnFloat(value){
				 var value=Math.round(parseFloat(value)*100)/100;
				 var xsd=value.toString().split(".");
				 if(xsd.length==1){
				 value=value.toString()+".00";
				 return value;
				 }
				 if(xsd.length>1){
				 if(xsd[1].length<2){
				 value=value.toString()+"0";
				 }
				 return value;
				 }
				}
				$scope.price=returnFloat($scope.price);
				//购买
				$scope.buy=function(dizhi,xingming,dianhua,num,totalprice){
					console.log(dizhi,xingming,dianhua,num,totalprice);
				}
				
				
			})
			app.controller('about',function($scope){
				
			})
			app.controller('contact',function($scope,$http){
				$scope.submit=function(name,phone,email,cnt){
					$http.post('api/liuyan.php',{name:name,phone:phone,email:email,cnt:cnt})
					.success(function(z){
						console.log(z);
						alert(z);
					})
				}
			})
			app.controller('news',function($scope,$http,$state){
				$scope.func_tejia=function(did){
					$state.go('cp_detail',{'did':did});
					console.log(did);
				};
			})
			app.controller('service',function($scope){
				
			})
			app.controller('cp',function($scope){
				
			})
		</script>
	</body>
</html>
